import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/comm/dropdownmenu.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

//盘库任务单
class InventoryOperationList extends StatefulWidget {
  final Map data;

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return InventoryOperationListState();
  }

  InventoryOperationList(this.data);
}

//ListWidget
class InventoryOperationListState extends State<InventoryOperationList> {
  List<dynamic> dropdownList = new List();
  bool load = true;
  String selectValue;
  String selectlibrary;
  List<dynamic> libraryData = new List();
  Color loadBgColor = Colors.white;
  List<dynamic> dataDetails = List();
  Color textColor;

  @override
  void initState() {
    super.initState();
    getDetails();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
          backgroundColor: Color(0XFF00A5F1),
          title: Text(
            "盘库单详情",
            style: TextStyle(fontSize: 18),
          ),
          elevation: 0,
          centerTitle: true,
        ),
        body: LoadBuilder(
            bgColor: loadBgColor,
            visibility: load,
            builder: Container(
                child: Column(
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Text(
                          "盘库单号：",
                          style: TextStyle(fontSize: 18),
                        ),
                        Text(widget.data["checktaskno"],
                            style: TextStyle(fontSize: 18, color: Colors.red))
                      ],
                    ),
                    Divider(
                      height: 1.0,
                      color: Colors.red,
                    ),
                    Expanded(
                      child: ListView.separated(
                          itemBuilder: (BuildContext context, int index) {
                            if(dataDetails.elementAt(index)["stocktaking"]=="未盘点"){
                              textColor=Colors.red;
                            }else{
                              textColor=Colors.green;
                            }
                            return GestureDetector(child:
                              Container(margin: EdgeInsets.only(left: 10,right: 10),child:
                              Column(
                                  children: <Widget>[
                                    Row(children: <Widget>[
                                      Expanded(child: Text(dataDetails.elementAt(index)["materialname"])),
                                      Text("${dataDetails.elementAt(index)["stocktaking"]}",style: TextStyle(color: textColor),),
                                    ],),
                                     Row(children: <Widget>[Expanded(child: Text("库区:${dataDetails.elementAt(index)["areaname"]}"),)],),
                                     Row(children: <Widget>[Expanded(child:  Text("货位:${dataDetails.elementAt(index)["locationcode"]}"),)],),
                                    Row(crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
                                      Expanded(child:  Text("数量:${dataDetails.elementAt(index)["totalcount"]}")),
                                      Expanded(child:  Text("单位:${dataDetails.elementAt(index)["baseunitname"]}")),
                                    ],
                                    )
                                  ])),
                              onTap: () {
                                if(dataDetails.elementAt(index)["stocktaking"]=="未盘点"){
                                  Navigator.of(context).pushNamed("/inventoryopr_detail",arguments: dataDetails.elementAt(index))..then((value) {
                                    if (value == "ok") {
                                      print("ok");
                                      getDetails();
                                    }
                                  });
                                }else{
                                  TostUtil.showToast("已盘点");
                                }
                              },
                            );
                          },
                          separatorBuilder: (BuildContext context, int index) =>
                              Divider(color: Colors.black26),
                          itemCount: dataDetails.length),
                    )
                  ],
                ))));
  }

  void getDetails() {
    dataDetails.clear();
    InternetAPI.getInstance()
        .post("WMS/MiWarehouseCheck/GetMiWarehouseCheckDetailsList", (data) {
      print(data);
      setState(() {
        dataDetails = data;
        load = false;
      });
    }, params: {
      'operaterUserId': DataSingleton().Data.id,
      'tenantId': DataSingleton().Data.tenantId,
      'Warehouseid': DataSingleton().warehouseChoice.id,
      'id': widget.data["id"],
      'pageNo': 1,
      'pageSize': 1000
    });
  }
}
